import { LvSizeLD } from '../core/api';
import { POSITION_MAP } from '../core/tooltipbase/tooltip-overlay-position';

export type ModalCallback = (value1?, value2?) => any;

export type ModalType = 'modal' | 'dialog' | 'drawer' | 'popover';

export type CompatibleDocument = {
  parentWindow?: Window;
} & Document;

export interface ModalButton<T = any> {
  label: string;
  id?: string;
  type?: string;
  size?: LvSizeLD;
  loadingText?: string;
  // Default: true, show loading automatically when a promise call back.
  autoLoading?: boolean;
  loading?: boolean;
  visible?: boolean;
  disabled?: boolean;
  tips?: string;
  onClick?: (modalInstance?, button?: ModalButton<T>) => void;
}

export enum ModalTypeEnum {
  MODAL = 'modal',
  DIALOG = 'dialog',
  DRAWER = 'drawer',
  POPOVER = 'popover',
}

export const MODAL_ADJUST_POSITION_MAP = [
  POSITION_MAP.topLeft,
  POSITION_MAP.rightTop,
  POSITION_MAP.bottomLeft,
  POSITION_MAP.leftTop,
  POSITION_MAP.leftBottom,
];

// If drawer scene, 4 enums of width can be set
export function genWidthByDrawEnum(options: any): void {
  if (options.lvType === ModalTypeEnum.DRAWER && 'lvWidth' in options) {
    switch (options.lvWidth) {
      case 'S':
        options.lvWidth = 416;
        break;
      case 'M':
        options.lvWidth = 608;
        break;
      case 'L':
        options.lvWidth = 896;
        break;
      case 'XL':
        options.lvWidth = 1232;
        break;
      default:
        break;
    }
  }
}
